/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package function;

import engine.skill.SkillBuffManager;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import mainpackage.Constant;
import mainpackage.GameBean;
import mainpackage.InputInterFace;
import mainpackage.MainCanvas;
import mainpackage.MainGame;
import mainpackage.MainLogic;
import mainpackage.ResManager;
import mainpackage.Tools;
import ui.UiEquipment;

/**
 *
 * @author foonwayx
 */
public class Team {

    /**
     * 队伍中没有自己的信息
     */
    private long[] lMemberID = new long[Constant.MAX_TEAM_MEMBER_NUM]; //队员ID
    private short[] shLevel = new short[Constant.MAX_TEAM_MEMBER_NUM]; //队员等级
    private byte[] byJob = new byte[Constant.MAX_TEAM_MEMBER_NUM];//队员职业
    private Image[] jobIcon = new Image[Constant.MAX_TEAM_MEMBER_NUM];//职业图片
    private String[] sNick = new String[Constant.MAX_TEAM_MEMBER_NUM]; //队员名称
    private short[] shHp = new short[Constant.MAX_TEAM_MEMBER_NUM];//当前血量
    private short[] shMaxHp = new short[Constant.MAX_TEAM_MEMBER_NUM];//最大血量
    private short[] shMp = new short[Constant.MAX_TEAM_MEMBER_NUM];//当前魔法量
    private short[] shMaxMp = new short[Constant.MAX_TEAM_MEMBER_NUM];//最大魔法值
    private byte[] byTeamLeader = new byte[Constant.MAX_TEAM_MEMBER_NUM]; //是否是队长
    //绘制队伍信息需要资源
    private Image[] imgArray = null;
    private String[] sArray = null;
    private int[] iArray = null;
    private byte byState = 0;
    private byte byUiState = 0;
    private int iPositionY = 0;
    private static String[] sOpArray; //队伍操作数组
    private byte bySubSelectIndex = 1;
    private byte bySelectIndex = 1;
    private boolean bUiKeyPressLock = false;
    private long lSponsorID = -1L;
    public boolean bShowRollPopUp = false;
    private byte byPopUpState = 1;

    public Team() {
        this.initTeam();
    }

    public void initTeam() {
        lMemberID = new long[Constant.MAX_TEAM_MEMBER_NUM]; //队员ID
        shLevel = new short[Constant.MAX_TEAM_MEMBER_NUM]; //队员等级
        byJob = new byte[Constant.MAX_TEAM_MEMBER_NUM];//队员职业
        jobIcon = new Image[Constant.MAX_TEAM_MEMBER_NUM];//职业图片
        sNick = new String[Constant.MAX_TEAM_MEMBER_NUM]; //队员名称
        shHp = new short[Constant.MAX_TEAM_MEMBER_NUM];//当前血量
        shMaxHp = new short[Constant.MAX_TEAM_MEMBER_NUM];//最大血量
        shMp = new short[Constant.MAX_TEAM_MEMBER_NUM];//当前魔法量
        shMaxMp = new short[Constant.MAX_TEAM_MEMBER_NUM];//最大魔法值
        byTeamLeader = new byte[Constant.MAX_TEAM_MEMBER_NUM]; //是否是队长
        for (byte i = 0; i < Constant.MAX_TEAM_MEMBER_NUM; i++) {
            lMemberID[i] = -1L;
            shLevel[i] = 0;
            byJob[i] = -1;
            jobIcon[i] = null;
            sNick[i] = null;
            shHp[i] = 1;
            shMaxHp[i] = 1;
            shMp[i] = 1;
            shMaxMp[i] = 1;
            byTeamLeader[i] = -1;
        }
    }

    /**
     * 
     */
    /**添加或是更新队伍一个成员
     * @param index    索引位置
     * @param lMemberID  成员ID
     * @param byLeader  队长
     * @param shLevel  等级
     * @param byJob //职业
     * @param sNick //名称
     * @param shHp  //血量
     * @param shMaxHp //最大血量
     * @param shMp  //魔法量
     * @param shMaxMp最大魔法量
     * @param iPlayerX 玩家位置
     * @param iPlayerY 
     */
    public void addMember(long lMemberID, byte byLeader, short shLevel, byte bySex, byte byJob, String sNick, short shHp, short shMaxHp, short shMp, short shMaxMp) {
        byte index = this.getMemberPos(lMemberID);
        if (index == -1) {
            index = this.getTeamEmptyPos();
        }
        this.lMemberID[index] = lMemberID;
        this.shLevel[index] = shLevel;
        this.byJob[index] = byJob;
        this.sNick[index] = sNick;
        this.shHp[index] = shHp;
        this.shMaxHp[index] = shMaxHp;
        this.shMp[index] = shMp;
        this.shMaxMp[index] = shMaxMp;
        this.byTeamLeader[index] = byLeader;
        Tools.printLog("this.shLevel[index]=" + this.shLevel[index]);
        if (byLeader == 1) {
            //队长有独占性，一个人是了，其他人就不是
            for (byte i = 0; i < Constant.MAX_TEAM_MEMBER_NUM; i++) {
                if (i != index) {
                    this.byTeamLeader[i] = 0;
                }
            }
        }
        try {
            if (bySex == Constant.PLAYER_SEX_MAN) {//性别：男
                if (byJob == Constant.PLAYER_OCCUPTION_ASSASSIN) {//职业为：刺客
                    jobIcon[index] = ResManager.createImage(1563, Constant.RES_PUBLIC_ONEROOM, Constant.RES_UI_PATH, false, -1);//男刺客
                } else if (byJob == Constant.PLAYER_OCCUPTION_MASTER) {//职业为：术士
                    jobIcon[index] = ResManager.createImage(1565, Constant.RES_PUBLIC_ONEROOM, Constant.RES_UI_PATH, false, -1);//男术士
                } else if (byJob == Constant.PLAYER_OCCUPTION_SWORD) {//职业为：武师
                    jobIcon[index] = ResManager.createImage(1567, Constant.RES_PUBLIC_ONEROOM, Constant.RES_UI_PATH, false, -1);//男武师
                }
            } else if (bySex == Constant.PLAYER_SEX_WOMAN) {//性别：女
                if (byJob == Constant.PLAYER_OCCUPTION_ASSASSIN) {//职业为：刺客
                    jobIcon[index] = ResManager.createImage(1564, Constant.RES_PUBLIC_ONEROOM, Constant.RES_UI_PATH, false, -1);//女刺客
                } else if (byJob == Constant.PLAYER_OCCUPTION_MASTER) {//职业为：术士
                    jobIcon[index] = ResManager.createImage(1566, Constant.RES_PUBLIC_ONEROOM, Constant.RES_UI_PATH, false, -1);//女术士
                } else if (byJob == Constant.PLAYER_OCCUPTION_SWORD) {//职业为：武师
                    jobIcon[index] = ResManager.createImage(1568, Constant.RES_PUBLIC_ONEROOM, Constant.RES_UI_PATH, false, -1);//女武师
                }
            }
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
//            System.out.print("加载职业图片出错");
        }
    }

    /**
     * 删除一个成员
     */
    public void deleteMember(byte index) {
        this.lMemberID[index] = -1L;
        this.shLevel[index] = 0;
        this.byJob[index] = -1;
        this.sNick[index] = null;
        this.shHp[index] = 1;
        this.shMaxHp[index] = 1;
        this.shMp[index] = 1;
        this.shMaxMp[index] = 1;
        this.jobIcon[index] = null;
    }

    /**
     * 找出一个队伍中空位
     * @return
     */
    public byte getTeamEmptyPos() {
        for (byte i = 0; i < Constant.MAX_TEAM_MEMBER_NUM; i++) {
            if (this.lMemberID[i] == -1) {
                return i;
            }
        }
        return 0;
    }

    /**
     * 检测索引位置是否有队伍成员
     * @param index
     * @return
     */
    public boolean checkHasMember(byte index) {
        if (index < Constant.MAX_TEAM_MEMBER_NUM) {
            return this.lMemberID[index] == -1 ? false : true;
        }
        return false;
    }

    /**
     * 根据玩家的ID获得玩家在队伍中的位置
     * @param lPlayerID
     * @return
     */
    public byte getMemberPos(long lPlayerID) {
        for (byte i = 0; i < Constant.MAX_TEAM_MEMBER_NUM; i++) {
            if (this.lMemberID[i] == lPlayerID) {
                return i;
            }
        }
        return -1;
    }

    /**
     * 获得当前队伍中队员的数量
     * @return
     */
    public byte getMemberNum() {
        byte byMemberNum = 0;
        for (byte i = 0; i < Constant.MAX_TEAM_MEMBER_NUM; i++) {
            if (this.lMemberID[i] != -1) {
                byMemberNum++;
            }
        }
        return byMemberNum;
    }

    //绘制UI界面的任务的组队解密
    public void drawTeam(Graphics g, int startX, int startY, Image numericPic) {
        if (getMemberNum() == 0) {
            return;
        }
        g.setColor(0x303c26);
        for (byte i = 0; i < Constant.MAX_TEAM_MEMBER_NUM; i++) {
            if (this.lMemberID[i] == -1) {
                continue;
            }
            //#if NOKIA_S60V5
             int iAvatarHeight = 31;
             int iBloodWidth = 80;
             int iBloodHeight = 6;
             int iBloodStartX = startX + 30;
             int iBloodStartY = startY + 18;
             Tools.drawHead(g, MainLogic.getInstance().uiInterFace.roamImgUiArray[17], jobIcon[i], startX, startY);
            //#else
//#            if(jobIcon[i] == null)
//#                continue;
//#            int iAvatarHeight = jobIcon[i].getHeight();
//#            int iBloodWidth = 46;
//#            int iBloodHeight = 4;
//#            int iBloodStartX = startX + jobIcon[i].getWidth() - 1;
//#            int iBloodStartY = startY + jobIcon[i].getHeight() - (iBloodHeight << 1) - 1;
//#            g.drawImage(this.jobIcon[i], startX, startY, 0);
            //#endif
            //绘制等级
            Tools.drawNumPic(g, numericPic, String.valueOf(this.shLevel[i]), (byte) 1, startX,
                    startY + iAvatarHeight - 7, (byte) 1);
            //填充血框、蓝框
            g.setColor(0x87888D);
            g.fillRect(iBloodStartX + 1, iBloodStartY + 1, iBloodWidth - 1, (iBloodHeight << 1) - 1);
            //绘制血框
            g.setColor(0x000000);
            g.drawRect(iBloodStartX, iBloodStartY, iBloodWidth, iBloodHeight);
            //绘制蓝框
            g.drawRect(iBloodStartX, iBloodStartY + iBloodHeight, iBloodWidth, iBloodHeight);
            //绘制血条
            Tools.drawBloodStrip(g, 0xFF0000, -1, iBloodWidth - 1, this.shMaxHp[i], this.shHp[i],
                    iBloodHeight - 1, iBloodStartX + 1, iBloodStartY + 1);
            //绘制蓝条
            Tools.drawBloodStrip(g, 0x00D7FF, -1, iBloodWidth - 1, this.shMaxMp[i], this.shMp[i],
                    iBloodHeight - 1, iBloodStartX + 1, iBloodStartY + iBloodHeight + 1);
            //#if NOKIA_S60V5
             //绘制buffer
             SkillBuffManager.drawBuff(g, lMemberID[i], iBloodStartX + 1, iBloodStartY - 9);
             startY += (iAvatarHeight - 1);
            //#else
//#            //绘制buffer
//#            SkillBuffManager.drawBuff(g, lMemberID[i], iBloodStartX + 1, startY + 1);
//#            startY += (iAvatarHeight - 1);
//#            //绘制蓝边
//#            g.setColor(0x00D7FF);
//#            g.fillRect(Constant.UI_START_X, Constant.UI_START_Y, 3, startY - Constant.UI_START_Y + 1);
            //#endif
        }
    }
    /******************查看队伍信息界面*************************************************/
    public static boolean bTeamLeader = false; //当前玩家是否是队长
    private byte byTeamMemberNum = 0;  //当前队伍的实际队员数量
    private int iSubPositionY = 0;
    private boolean bFlag = false;

    /**
     * 初始化队伍信息资源
     */
    public void initTeamInfo() {
//        addMember(11111, (byte) 0, (byte) 90, (byte) 1, (byte) 1, "这个杀手不太冷", (short) 1111, (short) 2222, (short) 1111, (short) 2222);
//        addMember(11112, (byte) 0, (byte) 91, (byte) 1, (byte) 2, "这个杀手有点冷", (short) 1131, (short) 2222, (short) 1111, (short) 2222);
//        addMember(11113, (byte) 0, (byte) 92, (byte) 1, (byte) 1, "这个杀手很冷", (short) 1111, (short) 2232, (short) 1111, (short) 2222);
//        addMember(11115, (byte) 0, (byte) 92, (byte) 1, (byte) 1, "这个杀手很冷", (short) 1111, (short) 2232, (short) 1111, (short) 2222);
        bUiKeyPressLock = false;
        //判断当前的玩家是否是队长
        bTeamLeader = this.isMeLeader();
        if (bTeamLeader) {
            this.sOpArray = new String[]{"私聊", "加好友", "交易", "查看", "提升队长", "踢出队伍"};
        } else {
            this.sOpArray = new String[]{"私聊", "加好友", "交易", "查看"};
        }
        this.sArray = new String[]{"队伍成员", "职业", " 等级", "姓名", "【", "】", "提示", "您确定要离开队伍么?", "离开队伍", "返回"};
        bySelectIndex = 1;
        this.bySubSelectIndex = 1;
        //#if NOKIA_S60V5
         this.iPositionY = Constant.UI_START_X + 70 + (Constant.FONT_SMALL_HEIGHT << 1);
        //#else
//#        this.iPositionY = 62 + (Constant.FONT_SMALL_HEIGHT + 5) * this.bySelectIndex - 2;
        //#endif
        this.byTeamMemberNum = this.getMemberNum();
        try {
            //#if NOKIA_S60V5
             this.imgArray = new Image[10];
             this.imgArray[0] = ResManager.createImage(90000041); //小箭头图片
             this.imgArray[1] = Tools.makeBlueMask(); //蓝色选择条
             this.imgArray[2] = ResManager.createImage(90000017);//背景图片
             this.imgArray[3] = Tools.makeTransparent(ResManager.createImage(90000051), 255); //边框图片
             this.imgArray[4] = ResManager.createImage(90000086);//蓝条
             this.imgArray[5] = ResManager.createImage(90000043);  //文字图片
             this.imgArray[6] = ResManager.createImage(90000085);//确认按钮图片
             this.imgArray[7] = ResManager.createImage(90000084);//方向键图片
             this.imgArray[8] = Tools.makeTransparent(Constant.DRAW_WIDTH, 20, 180, 0x000000);            //弹出层背后的遮罩层
             this.imgArray[9] = ResManager.createImage(90000044);            //白色的确定取消文字
            //#else
//#            this.imgArray = new Image[7];
//#            this.imgArray[0] = ResManager.createImage(90000041);  //箭头
//#            this.imgArray[1] = Tools.makeBlueMask(); //蓝色的遮罩
//#            this.imgArray[2] = ResManager.createImage(90000043);//返回，取消
            //#if NOKIA_S40V3 || MOTO || K790
            //#elif NORMAL_240_400
//# //            imgArray[3] = ResManager.createImage(90000017);
//# //            imgArray[3] = Tools.ZoomImage(imgArray[3], Constant.DRAW_WIDTH, Constant.DRAW_HEIGHT);
            //#else
//#            //背景图片
//#            //背景图片
//#            //背景图片
//#            //背景图片
//#            this.imgArray[3] = ResManager.createImage(90000017);  //背景图片
            //#endif
//#
//#            this.imgArray[4] = Tools.makeTransparent(Constant.DRAW_WIDTH, 20, 180, 0x000000); //弹出层背后的遮罩层
//#            this.imgArray[5] = Tools.makeTransparent(ResManager.createImage(90000051), 255);   //圆矩形边框
//#            this.imgArray[6] = ResManager.createImage(90000044);            //白色的确定取消文字
            //#endif
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 通过第几队友来获得队员的pos
     * @param index(第几个队友)
     */
    public byte getMemberPosByIndex(byte index) {
        byte place = 0;
        for (byte i = 0; i < Constant.MAX_TEAM_MEMBER_NUM; i++) {
            if (this.lMemberID[i] > 0) {
                place++;
                if (place == index) {
                    return i;
                }
            }
        }
        return 0;
    }

    /**
     * 更新队伍逻辑
     */
    public void updateTeamInfo() {
        if (this.getMemberNum() != this.byTeamMemberNum || this.bTeamLeader != this.isMeLeader()) {
            if (this.bTeamLeader != this.isMeLeader()) {
                this.bTeamLeader = this.isMeLeader();
                if (bTeamLeader) {
                    this.sOpArray = new String[]{"私聊", "加好友", "交易", "查看", "提升队长", "踢出队伍"};
                } else {
                    this.sOpArray = new String[]{"私聊", "加好友", "交易", "查看"};
                }
            }
            this.byTeamMemberNum = this.getMemberNum();
            this.iPositionY = Constant.UI_START_X + 62 + Constant.FONT_SMALL_HEIGHT;
            this.byUiState = 0;
            this.bySelectIndex = 1;
            this.bySubSelectIndex = 1;
        }
        switch (this.byUiState) {
            case 0:
                if (!this.bUiKeyPressLock) {
                    if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_UP, false)) {
                        if (this.bySelectIndex > 1) {
                            this.bySelectIndex = (byte) (this.bySelectIndex - 1);
                            this.byState = 3;
                            this.bUiKeyPressLock = true;
                            //#if NOKIA_S60V5
                             this.iArray = new int[]{2, 1, Constant.UI_START_X + 70 + (Constant.FONT_SMALL_HEIGHT << 1) + (this.bySelectIndex - 1) * (Constant.FONT_SMALL_HEIGHT + 20), 2, 50, 20};
                            //#else
//#                            this.iArray = new int[]{2, 1, 62 + (Constant.FONT_SMALL_HEIGHT + 5) * this.bySelectIndex - 2, 2, 50, 20};
                            //#endif
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_DOWN, false)) {
                        if (this.bySelectIndex < this.byTeamMemberNum) {
                            this.bySelectIndex = (byte) (this.bySelectIndex + 1);
                            this.byState = 4;
                            this.bUiKeyPressLock = true;
                            //#if NOKIA_S60V5
                             this.iArray = new int[]{1, 1, Constant.UI_START_X + 70 + (Constant.FONT_SMALL_HEIGHT << 1) + (this.bySelectIndex - 1) * (Constant.FONT_SMALL_HEIGHT + 20), 2, 50, 20};
                            //#else
//#                            this.iArray = new int[]{1, 1, 62 + (Constant.FONT_SMALL_HEIGHT + 5) * this.bySelectIndex - 2, 2, 50, 20};
                            //#endif
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_FIRE, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_5, false)) {
                        this.bySubSelectIndex = 1;
                        //#if NOKIA_S60V5
                         this.iSubPositionY = Constant.UI_START_Y + ((Constant.END_LINE - (sOpArray.length * 37 + 7)) >> 1) + 7 + (this.bySubSelectIndex - 1) * 37;
                        //#else
//#                        this.iSubPositionY = Constant.UI_START_Y + ((Constant.DRAW_HEIGHT - (sOpArray.length * 30 + 7)) >> 1) + 7 + (this.bySubSelectIndex - 1) * 30;
                        //#endif
                        this.byUiState = 1;
                        this.bUiKeyPressLock = false;
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false)) {
                        if (MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10301")
                                || MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10401")
                                || MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10501")) {
                            MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "您正在副本中，不允许离开队伍!", (byte) 1, (byte) -1);
                        } else {
                            this.byUiState = 2;
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {
                        Tools.openRoamMenu(false, (byte) 1, (byte) 8, 1);//返回菜单界面
                    }
                } else {
                    if (this.byState == 3 || this.byState == 4) {
                        this.iPositionY = Tools.updateLinePos(iArray, this.iPositionY);
                        if (this.iArray == null || this.iArray[1] == 0) {
                            this.bUiKeyPressLock = false;
                            this.byState = 0;
                        }
                    }
                }
                break;
            case 1:
                this.bFlag = this.bFlag ? false : true;
                if (!this.bUiKeyPressLock) {
                    if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_UP, false)) {
                        if (this.bySubSelectIndex > 1) {
                            this.bySubSelectIndex = (byte) (this.bySubSelectIndex - 1);
                            this.byState = 3;
                            this.bUiKeyPressLock = true;
                            //#if NOKIA_S60V5
                             this.iArray = new int[]{2, 1, Constant.UI_START_Y + ((Constant.END_LINE - (sOpArray.length * 37 + 7)) >> 1) + 7 + (this.bySubSelectIndex - 1) * 37, 2, 150, 20};
                            //#else
//#                            this.iArray = new int[]{2, 1, Constant.UI_START_Y + ((Constant.DRAW_HEIGHT - (sOpArray.length * 30 + 7)) >> 1) + 7 + (this.bySubSelectIndex - 1) * 30, 2, 150, 20};
                            //#endif
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_DOWN, false)) {
                        if (this.bySubSelectIndex < this.sOpArray.length) {
                            this.bySubSelectIndex = (byte) (this.bySubSelectIndex + 1);
                            this.byState = 4;
                            this.bUiKeyPressLock = true;
                            //#if NOKIA_S60V5
                             this.iArray = new int[]{1, 1, Constant.UI_START_Y + ((Constant.END_LINE - (sOpArray.length * 37 + 7)) >> 1) + 7 + (this.bySubSelectIndex - 1) * 37, 2, 150, 20};
                            //#else
//#                            this.iArray = new int[]{1, 1, Constant.UI_START_Y + ((Constant.DRAW_HEIGHT - (sOpArray.length * 30 + 7)) >> 1) + 7 + (this.bySubSelectIndex - 1) * 30, 2, 150, 20};
                            //#endif
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_FIRE, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_5, false)) {
                        byte byCurrentMemberPos = this.getMemberPosByIndex(this.bySelectIndex);
                        switch (this.bySubSelectIndex) {
                            case 1:
                                //私聊
                                GameBean.BY_PRE_GAME_UI_STATE = Constant.GAME_UI_TEAM_INFO;
                                GameBean.L_PLAYER_ID = this.lMemberID[byCurrentMemberPos];
                                UiEquipment.chatOtherplayerId = this.lMemberID[byCurrentMemberPos];//发送对象Id
                                MainLogic.getInstance().uiEquipment.chatOtherplayerName = this.sNick[byCurrentMemberPos];
                                if (MainLogic.getInstance().uiEquipment.chatOtherplayerName.equals(MainLogic.getInstance().gamePlayer.sPlayerName)) {
                                    MainLogic.getInstance().uiEquipment.chatOtherplayerName = "";
                                }
                                MainLogic.getInstance().uiEquipment.chatshoutType = 3;
                                MainLogic.getInstance().pushState(Constant.GAME_UI_CHAT, true);
                                MainLogic.getInstance().inputInterFace.setInputInterFace(Constant.GAME_UI_CHAT, "私聊发送聊天");
                                MainLogic.getInstance().inputInterFace.commonInput.setString(null);
                                MainGame.changeCanvas(MainLogic.getInstance().inputInterFace);
                                break;
                            case 2:
                                //加好友
                                GameBean.b_WAIT_NET_MSG_BACK = true;
                                GameBean.BY_CMD_FRIEND_NAME = this.sNick[byCurrentMemberPos];
                                GameBean.BY_CMD_FRIEND_TYPE = 1;
                                GameBean.BY_CMD_FRIEND_MODE = 1;
                                MainLogic.getInstance().send(Constant.MSG_NET_CMD_ADD_FRIEND, Constant.SOCKET_MSG_TYPE_LOGIC);
                                break;
                            case 3:
                                //交易
                                GameBean.L_PLAYER_ID = this.lMemberID[byCurrentMemberPos];
                                GameBean.BY_TYPE = 1;
                                GameBean.b_WAIT_NET_MSG_BACK = true;
                                GameBean.STR_CMD_PLAYER_NICK = this.sNick[byCurrentMemberPos];
                                MainLogic.getInstance().send(Constant.MSG_NET_CMD_TRADE_JOIN, Constant.SOCKET_MSG_TYPE_LOGIC);
                                break;
                            case 4:
                                //查看
                                GameBean.BY_PRE_GAME_UI_STATE = Constant.GAME_UI_TEAM_INFO;
                                GameBean.L_PLAYER_ID = this.lMemberID[byCurrentMemberPos];
                                GameBean.b_WAIT_NET_MSG_BACK = true;
                                MainLogic.getInstance().send(Constant.MSG_NET_CMD_OTHER_PLAYER_DETAIL, Constant.SOCKET_MSG_TYPE_LOGIC);
                                break;
                            case 5:
                                //提升队长
                                GameBean.L_PLAYER_ID = this.lMemberID[byCurrentMemberPos];
                                MainLogic.getInstance().send(Constant.MSG_NET_CMD_TEAM_CHANGE_LEADER, Constant.SOCKET_MSG_TYPE_LOGIC);
                                break;
                            case 6:
                                //剔除队伍
                                if (MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10301")
                                        || MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10401")
                                        || MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10501")) {
                                    MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "您与对方正在副本中，不允许将对方踢出队伍!", (byte) 1, (byte) -1);
                                } else {
                                    GameBean.b_WAIT_NET_MSG_BACK = true;
                                    GameBean.L_PLAYER_ID = this.lMemberID[byCurrentMemberPos];
                                    MainLogic.getInstance().send(Constant.MSG_NET_CMD_TEAM_LEAVE, Constant.SOCKET_MSG_TYPE_LOGIC);
                                }
                                break;
                        }
                        this.byUiState = 0;
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {
                        this.byUiState = 0;
                    }
                } else {
                    if (this.byState == 3 || this.byState == 4) {
                        this.iSubPositionY = Tools.updateLinePos(iArray, this.iSubPositionY);
                        if (this.iArray == null || this.iArray[1] == 0) {
                            this.bUiKeyPressLock = false;
                            this.byState = 0;
                        }
                    }
                }
                break;
            case 2:
                if (this.byPopUpState < 4) {
                    this.byPopUpState++;
                    return;
                }
                if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {
                    this.byUiState = 0;
                } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_5, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_FIRE, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false)) {
                    this.byUiState = 0;
                    GameBean.L_PLAYER_ID = MainLogic.getInstance().gamePlayer.lPlayerID;
                    MainLogic.getInstance().send(Constant.MSG_NET_CMD_TEAM_LEAVE, Constant.SOCKET_MSG_TYPE_LOGIC);
                    this.teamLeave(MainLogic.getInstance().gamePlayer.lPlayerID);
                }
                break;
        }
        MainCanvas.clearInput();
    }

    /**
     * 绘制队员界面
     * @param g 
     */
    public void drawTeamInfo(Graphics g) {
        int startX;
        int startY;
        byte j = 1;
        //#if NOKIA_S60V5
         Tools.drawS60V5Frame(g, this.imgArray[2], this.imgArray[7], this.imgArray[6], this.imgArray[4], null, this.sArray[0]);
         startX = Constant.UI_START_X + ((Constant.DRAW_WIDTH - Constant.FONT_SMALL.stringWidth(this.sArray[1] + this.sArray[2] + this.sArray[3]) - 4 * Constant.FONT_CHAR_WIDTH) >> 1);
         startY = Constant.UI_START_Y + 55;
         Tools.drawShadowString(g, (byte) 1, this.sArray[1], startX, startY, 0x0099ff, 0x000000);
         Tools.drawShadowString(g, (byte) 1, this.sArray[2], startX + Constant.FONT_CHAR_WIDTH + Constant.FONT_SMALL.stringWidth(this.sArray[1]), startY, 0x0099ff, 0x000000);
         Tools.drawShadowString(g, (byte) 1, this.sArray[3], startX + 2 * Constant.FONT_CHAR_WIDTH + Constant.FONT_SMALL.stringWidth(this.sArray[1] + this.sArray[2]), startY, 0x0099ff, 0x000000);
         Tools.drawArrow(g, this.imgArray[0], (byte) 1, Constant.UI_START_X + 20, startY + ((Constant.FONT_SMALL_HEIGHT - 7) >> 1));
         Tools.drawArrow(g, this.imgArray[0], (byte) 2, Constant.UI_START_X + Constant.DRAW_WIDTH - 25, startY + ((Constant.FONT_SMALL_HEIGHT - 7) >> 1));
         Tools.drawSelectMask(g, (byte) 1, this.imgArray[1], Constant.UI_START_X, Constant.UI_START_Y + 58 + Constant.FONT_SMALL_HEIGHT, Constant.DRAW_WIDTH);
         startY = Constant.UI_START_Y + 68 + Constant.FONT_SMALL_HEIGHT;
         startX = Constant.UI_START_X + 24;
         for (byte i = 0; i < Constant.MAX_TEAM_MEMBER_NUM; i++) {
             if (this.lMemberID[i] == -1) {
                 continue;
             }
             //职业
             Tools.drawShadowString(g, (byte) 1, this.sArray[4] + Tools.getJobName(this.byJob[i]) + this.sArray[5], startX, startY, this.bySelectIndex == j ? 0x00ccff : 0xFFFFFF, 0x000000);
             //等级
             Tools.drawShadowString(g, (byte) 1, String.valueOf(this.shLevel[i]), startX + Constant.FONT_SMALL.stringWidth(this.sArray[4] + Tools.getJobName(this.byJob[i]) + this.sArray[5]) + 4, startY, this.bySelectIndex == j ? 0x00ccff : 0xFFFFFF, 0x000000);
             //名称
             Tools.drawShadowString(g, (byte) 1, this.sNick[i], startX + 5 * Constant.FONT_CHAR_WIDTH + 12, startY, this.bySelectIndex == j ? 0x00ccff : 0xFFFFFF, 0x000000);
             startY = startY + Constant.FONT_SMALL_HEIGHT + 20;
             j++;
         }
         //绘制选中蓝条
         Tools.drawSelectMask(g, (byte) 1, this.imgArray[1], Constant.UI_START_X, this.iPositionY, Constant.DRAW_WIDTH);
         switch (this.byUiState) {
             case 1:
                 //黑色的遮罩层
                 Tools.drawTilePic(g, (byte) 2, Constant.UI_START_X, Constant.UI_START_Y, Constant.END_LINE - 45, this.imgArray[8], 0, 0, Constant.DRAW_WIDTH, 10, Constant.TRANS_NONE);
                 Tools.drawPopOperation(g, this.imgArray[3], 0x989898, 0x666666, this.sOpArray, 100, 30, 7, 0xFFFFFF, 0x00ccff, bySubSelectIndex, 0, 0);
                 //绘制选中横条
                 Tools.drawGapSlectMask(g, this.imgArray[1], this.imgArray[0], this.bFlag, 30, Constant.UI_START_X, this.iSubPositionY, Constant.DRAW_WIDTH);
                 break;
             case 2:
                 Tools.drawPopUp(g, this.byPopUpState, Constant.UI_START_X + 25, Constant.UI_START_Y + ((Constant.END_LINE - 120) >> 1), 310, 120, this.imgArray[3], 0x989898, this.imgArray[9], 22, 0, 21, 10, this.imgArray[9], 0, 0, 22, 10, this.sArray[6], this.sArray[7]);
                 break;
         }
         //绘制文字
         g.drawRegion(this.imgArray[5], 0, 79, 96, 24, Constant.TRANS_NONE, Constant.UI_START_X + 252, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 38, Graphics.TOP | Graphics.LEFT);
         g.drawRegion(this.imgArray[5], 48, 0, 48, 24, Constant.TRANS_NONE, Constant.UI_START_X + 12, Constant.UI_START_Y + Constant.DRAW_HEIGHT - 38, Graphics.TOP | Graphics.LEFT);
        //#else
        //#if NOKIA_E72
//#         Tools.drawE72Frame(g, this.imgArray[3],this.sArray[8],this.sArray[9], this.sArray[0]);
        //#else
//#        Tools.drawFrame(g, this.imgArray[3], this.imgArray[1], this.sArray[8], this.sArray[9], this.sArray[0]);
        //#endif
//#        startX = Constant.UI_START_X + ((Constant.DRAW_WIDTH - Constant.FONT_SMALL.stringWidth(this.sArray[1] + this.sArray[2] + this.sArray[3]) - 2 * Constant.FONT_CHAR_WIDTH) >> 1);
//#        startY = Constant.UI_START_Y + 45 - Constant.FONT_SMALL_HEIGHT;
//#        Tools.drawShadowString(g, (byte) 1, this.sArray[1], startX, startY, 0x0099ff, 0x000000);
//#        Tools.drawShadowString(g, (byte) 1, this.sArray[2], startX + Constant.FONT_CHAR_WIDTH + Constant.FONT_SMALL.stringWidth(this.sArray[1]), startY, 0x0099ff, 0x000000);
//#        Tools.drawShadowString(g, (byte) 1, this.sArray[3], startX + 2 * Constant.FONT_CHAR_WIDTH + Constant.FONT_SMALL.stringWidth(this.sArray[1] + this.sArray[2]), startY, 0x0099ff, 0x000000);
//#        Tools.drawArrow(g, this.imgArray[0], (byte) 1, Constant.UI_START_X + 10, startY + ((Constant.FONT_SMALL_HEIGHT - 7) >> 1));
//#        Tools.drawArrow(g, this.imgArray[0], (byte) 2, Constant.UI_START_X + Constant.DRAW_WIDTH - 15, startY + ((Constant.FONT_SMALL_HEIGHT - 7) >> 1));
//#        Tools.drawSelectMask(g, (byte) 1, this.imgArray[1], Constant.UI_START_X, Constant.UI_START_Y + 50, Constant.DRAW_WIDTH);
//#        startY = Constant.UI_START_Y + 60;
//#
//#        startX = Constant.UI_START_X + 12;
//#        for (byte i = 0; i < Constant.MAX_TEAM_MEMBER_NUM; i++) {
//#            if (this.lMemberID[i] == -1) {
//#                continue;
//#            }
//#            //职业
//#            Tools.drawShadowString(g, (byte) 1, this.sArray[4] + Tools.getJobName(this.byJob[i]) + this.sArray[5], startX, startY, this.bySelectIndex == j ? 0x00ccff : 0xFFFFFF, 0x000000);
//#            //等级
//#            Tools.drawShadowString(g, (byte) 1, String.valueOf(this.shLevel[i]), startX + Constant.FONT_SMALL.stringWidth(this.sArray[4] + Tools.getJobName(this.byJob[i]) + this.sArray[5]) + 4, startY, this.bySelectIndex == j ? 0x00ccff : 0xFFFFFF, 0x000000);
//#            //名称
//#            Tools.drawShadowString(g, (byte) 1, this.sNick[i], startX + 5 * Constant.FONT_CHAR_WIDTH + 12, startY, this.bySelectIndex == j ? 0x00ccff : 0xFFFFFF, 0x000000);
//#            startY = startY + Constant.FONT_SMALL_HEIGHT + 5;
//#            j++;
//#        }
//#        //绘制选中蓝条
//#        Tools.drawSelectMask(g, (byte) 1, this.imgArray[1], Constant.UI_START_X, this.iPositionY, Constant.DRAW_WIDTH);
//#        switch (this.byUiState) {
//#            case 1:
//#                //黑色的遮罩层
//#                Tools.drawTilePic(g, (byte) 2, Constant.UI_START_X, Constant.UI_START_Y, Constant.DRAW_HEIGHT, this.imgArray[4], 0, 0, Constant.DRAW_WIDTH, 10, Constant.TRANS_NONE);
//#                Tools.drawPopOperation(g, this.imgArray[5], 0x989898, 0x666666, this.sOpArray, 82, 23, 7, 0xFFFFFF, 0x00ccff, bySubSelectIndex, 0, 0);
//#                //绘制选中横条
//#                Tools.drawGapSlectMask(g, this.imgArray[1], this.imgArray[0], this.bFlag, 23, Constant.UI_START_X, this.iSubPositionY, Constant.DRAW_WIDTH);
//#                break;
//#            case 2:
//#                Tools.drawPopUp(g, this.byPopUpState, Constant.UI_START_X + 4, Constant.UI_START_Y + ((Constant.DRAW_HEIGHT - 80) >> 1), 232, 80, this.imgArray[5], 0x989898, this.imgArray[6], 0, 0, 22, 10, this.imgArray[6], 22, 0, 21, 10, this.sArray[6], this.sArray[7]);
//#                break;
//#        }
        //#endif
    }

    /**
     * 清除队伍界面的资源
     */
    public void clearTeamInfo() {
        this.iArray = null;
        this.sArray = null;
        this.imgArray = null;
        this.sOpArray = null;
    }

    /*************end****************************************************/
    //队伍的人数
    public byte getTeamMemberNum() {
        byte memberNum = 0;
        for (short i = 0; i < Constant.MAX_TEAM_MEMBER_NUM; i++) {
            if (this.lMemberID[i] > 0) {
                memberNum++;
            }
        }
        return memberNum;
    }

    /**
     * 判读是当前玩家是否是队长
     * @return
     */
    public boolean isMeLeader() {
        //判断当前的玩家是否是队长
        if (this.getMemberNum() == 0) {
            return false;
        } else {
            for (byte i = 0; i < Constant.MAX_TEAM_MEMBER_NUM; i++) {
                if (this.lMemberID[i] > 0 && this.byTeamLeader[i] == 1) {
                    return false;
                }
            }
            return true;
        }
    }

    /**
     * 解散队伍
     */
    public void teamDismiss() {
        GameBean.b_WAIT_NET_MSG_BACK = false;
        for (byte i = 0; i < Constant.MAX_TEAM_MEMBER_NUM; i++) {
            this.deleteMember(i);
            //添加提示
//            MainLogic.getInstance().uiEquipment.getChatInformation(100,
//                    "", (byte) 5, " 您所在的队伍已经解散!");
        }
        MainLogic.getInstance().pushState(Constant.GAME_UI_ROAM, true);
    }

    /**
     * 离开队伍
     * @param playerID   离开队伍的玩家的ID
     */
    public void teamLeave(long playerID) {
        GameBean.b_WAIT_NET_MSG_BACK = false;
        if (playerID == MainLogic.getInstance().gamePlayer.lPlayerID) {
            for (byte i = 0; i < Constant.MAX_TEAM_MEMBER_NUM; i++) {
                this.deleteMember(i);
            }
            //添加提示
            MainLogic.getInstance().uiEquipment.getChatInformation(100,
                    "", (byte) 5, " 您离开了队伍!");
            MainLogic.getInstance().pushState(Constant.GAME_UI_ROAM, true);
        } else if (this.getMemberNum() < 2) {
            teamDismiss();
        } else {
            byte index = this.getMemberPos(playerID);
            if (index != -1) {
                String sMemberName = this.sNick[index];
                this.deleteMember(index);
                this.bySelectIndex = 3;
                this.bySubSelectIndex = 1;
                MainLogic.getInstance().uiEquipment.getChatInformation(100,
                        "", (byte) 5, sMemberName + "离开了队伍!");
                sMemberName = null;
                MainLogic.getInstance().pushState(Constant.GAME_UI_ROAM, true);
            } else {
                MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "该玩家不在队伍中!");
            }

        }
    }

    /***********************************************************组队回应***************************************************************/
    /**
     * 组队提示信息
     */
    public void initTeamAnswer() {
        //弹出层的标题
        try {
            //#if NOKIA_S60V5
             this.imgArray = new Image[5];
             this.imgArray[0] = Tools.makeTransparent(ResManager.createImage(90000051), 255);
             this.imgArray[1] = ResManager.createImage(90000044);
             this.imgArray[2] = ResManager.createImage(90000043);//文字
             this.imgArray[3] = ResManager.createImage(90000086);
             this.imgArray[4] = ResManager.createImage(90000090);
            //#else
//#            this.imgArray = new Image[2];
//#            this.imgArray[0] = Tools.makeTransparent(ResManager.createImage(90000051), 255);
//#            this.imgArray[1] = ResManager.createImage(90000044);
            //#endif
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
//            System.out.print("弹出层图片载入异常");
        }
    }

    /**
     * 打开组队界面
     * @param lPlayerID
     * @param mess 
     */
    public void openTeamAnswer(long lPlayerID, String mess) {
         if(GameBean.BL_PLAYER_HANGUP)
         {
            GameBean.L_PLAYER_ID = this.lSponsorID;
            GameBean.BY_APPLY_RESULT = 1;
            MainLogic.getInstance().send(Constant.MSG_NET_CMD_TEAM_ANSWER, Constant.SOCKET_MSG_TYPE_LOGIC);    
         }
          else
         {
        this.sArray = new String[]{"组队邀请", mess};
        this.lSponsorID = lPlayerID;
        MainLogic.getInstance().pushState(Constant.GAME_UI_TEAM_ANSWER, true);
        }
    }

    /**
     * 更新组队逻辑
     */
    public void updateTeamAnswer() {
        if (this.byState < 4) {
            this.byState++;
        } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false)
                || MainCanvas.keyPressedLogic(Constant.GAME_KEY_FIRE, false)
                || MainCanvas.keyPressedLogic(Constant.GAME_KEY_5, false)) {
            //同意加入队伍
            GameBean.L_PLAYER_ID = this.lSponsorID;
            GameBean.BY_APPLY_RESULT = 1;
            MainLogic.getInstance().send(Constant.MSG_NET_CMD_TEAM_ANSWER, Constant.SOCKET_MSG_TYPE_LOGIC);
            MainLogic.getInstance().pushState(Constant.GAME_UI_ROAM, true);
        } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {
            //拒绝加入队伍
            GameBean.L_PLAYER_ID = this.lSponsorID;
            GameBean.BY_APPLY_RESULT = 0;
            MainLogic.getInstance().send(Constant.MSG_NET_CMD_TEAM_ANSWER, Constant.SOCKET_MSG_TYPE_LOGIC);
            MainLogic.getInstance().pushState(Constant.GAME_UI_ROAM, true);
        }
        MainCanvas.clearInput();
    }

    /**
     * 绘制弹出组队邀请
     * @param g 
     */
    public void drawTeamAnswer(Graphics g) {
        //#if NOKIA_S60V5
         Tools.drawPopUp(g, this.byState, Constant.UI_START_X + 25, Constant.UI_START_Y + ((Constant.DRAW_HEIGHT - 120) >> 1), 310, 120, this.imgArray[0], 0x9c9c9c, this.imgArray[1], 22, 0, 21, 10, this.imgArray[1], 0, 0, 22, 10, this.sArray[0], this.sArray[1]);
         Tools.drawBottom(g, this.imgArray[2], this.imgArray[4], this.imgArray[3]);
        //#else
//#        Tools.drawPopUp(g, this.byState, Constant.UI_START_X + ((Constant.DRAW_WIDTH - 232) >> 1), Constant.UI_START_Y + ((Constant.DRAW_HEIGHT - 80) >> 1), 232, 80, this.imgArray[0], 0x989898, this.imgArray[1], 0, 0, 22, 10, this.imgArray[1], 22, 0, 21, 10, this.sArray[0], this.sArray[1]);
        //#endif
    }

    /**
     * 清除组队资源
     */
    public void clearTeamAnswer() {
        this.sArray = null;
        this.imgArray = null;
    }
    /*****************************组队获得好东西roll界面******************/
    public String[] sRollItems = null;
    public byte byRollItemIndex = 0;
    private byte byWaitRollTime = 0;
    private short shHeight = 0;
    private byte byTime = 0;
    public boolean bRollTimeStart = false;
    public long lRollStartTime = 0L;
    public byte byRollTimeLeave = 0; //还剩下的roll的时间
    public boolean bCanRoll = false;
    public byte byCurrentRollIndex = 0;
    private Image[] rollItemImg = null;
    private String[] sRollItemArray = null;
    //打开物品roll界面

    public void showItemsRoll(byte byWaitTime) {
        this.byWaitRollTime = byWaitTime;
        this.sRollItemArray = new String[]{"物品需求(倒计时： <k", "> )", "需求", "放弃"};
        this.initItemRoll();
    }

    /**
     * 组队获得物品roll
     */
    public void initItemRoll() {
        //弹出层的标题
        try {
            //弹出层的图片数组
            //#if NOKIA_S60V5
             switch (MainLogic.getInstance().byGameState) {
                 case Constant.GAME_UI_ROAM:
                     rollItemImg = new Image[4];
                     rollItemImg[1] = ResManager.createImage(90000043);
                     rollItemImg[2] = ResManager.createImage(90000086);
                     rollItemImg[3] = ResManager.createImage(90000090);
                     break;
                 default:
                     rollItemImg = new Image[1];
                     break;
 
             }
             rollItemImg[0] = Tools.makeTransparent(ResManager.createImage(90000051), 255);
            //#else
//#            rollItemImg = new Image[1];
//#            rollItemImg[0] = Tools.makeTransparent(ResManager.createImage(90000051), 255);
            //#endif
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
//            System.out.print("弹出层图片载入异常");
        }
        this.bShowRollPopUp = true;
        this.byRollItemIndex = 0;
        this.bRollTimeStart = false;
        this.lRollStartTime = 0L;
        this.byRollTimeLeave = this.byWaitRollTime;
        this.bCanRoll = true;
        this.byCurrentRollIndex = 0;
        if (Constant.FONT_SMALL.stringWidth(this.sRollItems[0]) - 3 * Constant.FONT_CHAR_WIDTH > 200) {
            this.shHeight = 100;
        } else {
            this.shHeight = 80;
        }
    }

    /**
     * 物品roll的结果
     * @param playerName
     * @param result 
     */
    public void rollItemResult(String playerName, byte result) {
        if (this.sRollItems == null) {
            this.clearItemRoll();
            return;
        }
        if (result == 0) {
            MainLogic.getInstance().uiEquipment.getChatInformation(100, "", (byte) 3, playerName + "放弃了“" + this.sRollItems[2 * byCurrentRollIndex + 1] + "”");
        } else {
            MainLogic.getInstance().uiEquipment.getChatInformation(100,
                    "", (byte) 3, playerName + "选择了需求“" + this.sRollItems[2 * byCurrentRollIndex + 1] + "”,需求点数:" + result);
        }
        if (this.byCurrentRollIndex == this.sRollItems.length - 1) {
            this.clearItemRoll();
        }
    }

    /**
     * 更新组队rool物品界面逻辑
     */
    public void updateItemRoll() {
        if (!bCanRoll) {
            return;
        }
        if (this.byRollItemIndex >= (this.sRollItems.length >> 1)) {
            this.clearItemRoll();
            return;
        }
        if (this.byState < 4) {
            this.byState++;
        } else {
            if (!bRollTimeStart) {
                this.bRollTimeStart = true;
                this.lRollStartTime = System.currentTimeMillis();
                this.byRollTimeLeave = this.byWaitRollTime;
            }
            if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false)
                    || MainCanvas.keyPressedLogic(Constant.GAME_KEY_FIRE, false)
                    || MainCanvas.keyPressedLogic(Constant.GAME_KEY_5, false)) {
                //需求物品
                this.byState = 1;
                this.byCurrentRollIndex = this.byRollItemIndex;
                this.byRollItemIndex++;
                this.bRollTimeStart = false;
                this.bCanRoll = false;
                if (this.byRollItemIndex < (this.sRollItems.length >> 1)) {
                    if (Constant.FONT_SMALL.stringWidth(this.sRollItems[byRollItemIndex << 1]) - 3 * Constant.FONT_CHAR_WIDTH > 200) {
                        this.shHeight = 100;
                    } else {
                        this.shHeight = 80;
                    }
                }
                GameBean.BY_APPLY_RESULT = 1;
                MainLogic.getInstance().send(Constant.MSG_NET_CMD_TEAM_ROLL, Constant.SOCKET_MSG_TYPE_LOGIC);
            } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {
                //放弃物品
                this.byState = 1;
                this.byCurrentRollIndex = this.byRollItemIndex;
                this.byRollItemIndex++;
                this.bRollTimeStart = false;
                this.bCanRoll = false;
                if (this.byRollItemIndex < (this.sRollItems.length >> 1)) {
                    if (Constant.FONT_SMALL.stringWidth(this.sRollItems[byRollItemIndex << 1]) - 3 * Constant.FONT_CHAR_WIDTH > 200) {
                        this.shHeight = 100;
                    } else {
                        this.shHeight = 80;
                    }
                }
                GameBean.BY_APPLY_RESULT = 0;
                MainLogic.getInstance().send(Constant.MSG_NET_CMD_TEAM_ROLL, Constant.SOCKET_MSG_TYPE_LOGIC);
            } else {
                int intevel = (int) ((System.currentTimeMillis() - this.lRollStartTime) / 1000);
                if (intevel > this.byWaitRollTime) {
                    this.byState = 1;
                    this.byCurrentRollIndex = this.byRollItemIndex;
                    this.byRollItemIndex++;
                    this.bRollTimeStart = false;
                    this.bCanRoll = false;
                    if (this.byRollItemIndex < (this.sRollItems.length >> 1)) {
                        if (Constant.FONT_SMALL.stringWidth(this.sRollItems[byRollItemIndex << 1]) - 3 * Constant.FONT_CHAR_WIDTH > 200) {
                            this.shHeight = 100;
                        } else {
                            this.shHeight = 80;
                        }
                    }
                } else {
                    this.byRollTimeLeave = (byte) (this.byWaitRollTime - intevel);
                }
            }

        }
    }

    /**
     * 绘制组队roll物品
     * @param g 
     */
    public void drawItemRoll(Graphics g) {
        if (!bCanRoll) {
            return;
        }
        //#if NOKIA_S60V5
         Tools.drawPopUp(g, this.byState, Constant.UI_START_X + 25, Constant.UI_START_Y + ((Constant.END_LINE - this.shHeight) >> 1), 310, this.shHeight, this.rollItemImg[0], 0x9c9c9c, null, 0, 0, 0, 0, null, 0, 0, 0, 0, null, null);
         if (this.byState == 4) {
             //绘制物品名称
             Tools.drawParagraph(g, Constant.UI_START_X + 35, Constant.UI_START_Y + ((Constant.END_LINE - this.shHeight) >> 1) + 35, 270, this.sRollItems[this.byRollItemIndex << 1], 0xFFFFFF, 18, -1);
             Tools.drawShadowString(g, (byte) 1, this.sRollItemArray[2], Constant.UI_START_X + 35, Constant.UI_START_Y + ((Constant.END_LINE - this.shHeight) >> 1) + this.shHeight - 10 - Constant.FONT_SMALL_HEIGHT, 0xFFFFFF, 0x000000);
             Tools.drawShadowString(g, (byte) 1, this.sRollItemArray[3], Constant.UI_START_X + Constant.DRAW_WIDTH - 35 - Constant.FONT_SMALL.stringWidth(this.sRollItemArray[3]), Constant.UI_START_Y + ((Constant.END_LINE - this.shHeight) >> 1) + this.shHeight - 10 - Constant.FONT_SMALL_HEIGHT, 0xFFFFFF, 0x000000);
             //绘制标题
             Tools.drawParagraph(g, Constant.UI_START_X + 25 + ((310 - Constant.FONT_SMALL.stringWidth(this.sRollItemArray[0] + this.byRollTimeLeave + this.sRollItemArray[1])) >> 1), Constant.UI_START_Y + ((Constant.END_LINE - this.shHeight) >> 1) + 3 + ((25 - Constant.FONT_SMALL_HEIGHT) >> 1), 280, this.sRollItemArray[0] + this.byRollTimeLeave + this.sRollItemArray[1], 0xFFFFFF, 18, -1);
         }
         switch (MainLogic.getInstance().byGameState) {
             case Constant.GAME_UI_ROAM:
                 Tools.drawBottom(g, this.imgArray[1], this.imgArray[2], this.imgArray[3]);
                 break;
         }
        //#else
//#        int startX = Constant.UI_START_X + ((Constant.DRAW_WIDTH - 232) >> 1);
//#        Tools.drawPopUp(g, this.byState, startX, Constant.UI_START_Y + ((Constant.DRAW_HEIGHT - this.shHeight) >> 1), 232, this.shHeight, this.rollItemImg[0], 0x989898, null, 0, 0, 0, 0, null, 0, 0, 0, 0, null, null);
//#        if (this.byState == 4) {
//#            //绘制物品名称
//#            Tools.drawParagraph(g, startX + 16, Constant.UI_START_Y + ((Constant.DRAW_HEIGHT - this.shHeight) >> 1) + 25, 200, this.sRollItems[this.byRollItemIndex << 1], 0xFFFFFF, 18, -1);
//#            Tools.drawShadowString(g, (byte) 1, this.sRollItemArray[2], startX + 26, Constant.UI_START_Y + ((Constant.DRAW_HEIGHT - this.shHeight) >> 1) + this.shHeight - 10 - Constant.FONT_SMALL_HEIGHT, 0xFFFFFF, 0x000000);
//#            Tools.drawShadowString(g, (byte) 1, this.sRollItemArray[3], startX + 232 - 30 - Constant.FONT_SMALL.stringWidth(this.sRollItemArray[3]), Constant.UI_START_Y + ((Constant.DRAW_HEIGHT - this.shHeight) >> 1) + this.shHeight - 10 - Constant.FONT_SMALL_HEIGHT, 0xFFFFFF, 0x000000);
//#            //绘制标题
//#            Tools.drawParagraph(g, startX + ((Constant.DRAW_WIDTH - 8 - Constant.FONT_SMALL.stringWidth(this.sRollItemArray[0] + this.byRollTimeLeave + this.sRollItemArray[1])) >> 1), Constant.UI_START_Y + ((Constant.DRAW_HEIGHT - this.shHeight) >> 1) + 3 + ((14 - Constant.FONT_SMALL_HEIGHT) >> 1), 180, this.sRollItemArray[0] + this.byRollTimeLeave + this.sRollItemArray[1], 0xFFFFFF, 18, -1);
//#        }
        //#endif
    }

    /**
     * 清除组队roll物品资源
     */
    public void clearItemRoll() {
        this.bShowRollPopUp = false;
        this.byWaitRollTime = 0;
        this.byRollItemIndex = -1;
        this.sRollItems = null;
        this.rollItemImg = null;
        this.sRollItemArray = null;
    }
}
